
// 获取h5埋点格式化后的数据
export default (
	{
		channel = '',
		platform = '',
		userId = '',
	} = {},
	data = [],
) => {
	if (!Array.isArray(data)) data = [data]

	const records = data.map(item => {
		const _pageParams = JSON.stringify(item.pageParams)
		const _parentParams = JSON.stringify(item.parentParams)
		const _actionParams = JSON.stringify(item.actionParams)

		return {
			triggerTime: new Date().getTime().toString(),
			userId,
			page: item.page,
			pageParams: _pageParams === '{}' ? '' : _pageParams,
			parentPage: item.parentPage,
			parentParams: _parentParams === '{}' ? '' : _parentParams,
			action: item.type || item.action,
			actionParams: _actionParams === '{}' ? '' : _actionParams,
			target: item.target,
		}
	})
	
	return {
		base: {
			channel,
			platform,
		},
		records,
	};
};